﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BaccaratRally.DataKernel.Entity
{
    [BaccaratRally.DataKernel.Entity.SqlTableAttribute("Bets")]
    public class BetItem : BaccaratRally.DataKernel.Entity.EntityBase
    {

        #region data fields
        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("BetID", true, true, false, false)]
        public System.Int32 BetID { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("AccountName", false, false, false, false)]
        public System.String AccountName { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("AccountPos", false, false, false, false)]
        public System.String AccountPos { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("TableNo", false, false, false, false)]
        public System.Byte TableNo { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("BetStatus", false, false, false, false)]
        public System.Byte BetStatus { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("BetDirection", false, false, false, false)]
        public System.String BetDirection { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("BetTime", false, false, false, false)]
        public System.DateTime BetTime { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("BetSize", false, false, false, false)]
        public System.Decimal BetSize { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("BetResult", false, false, true, false)]
        public System.String BetResult { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("BetProfit", false, false, true, false)]
        public System.Decimal BetProfit { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("SetTime", false, false, true, false)]
        public System.DateTime SetTime { get; set; }

        #endregion

        internal override void ReBuildInstance(System.Data.SqlClient.SqlDataReader reader)
        {
            this.BetID = GetReaderValue<System.Int32>(reader, "BetID");
            this.AccountName = GetReaderValue<System.String>(reader, "AccountName");
            this.AccountPos = GetReaderValue<System.String>(reader, "AccountPos");
            this.TableNo = GetReaderValue<System.Byte>(reader, "TableNo");
            this.BetStatus = GetReaderValue<System.Byte>(reader, "BetStatus");
            this.BetDirection = GetReaderValue<System.String>(reader, "BetDirection");
            this.BetTime = GetReaderValue<System.DateTime>(reader, "BetTime");
            this.BetSize = GetReaderValue<System.Decimal>(reader, "BetSize");
            this.BetResult = GetReaderValue<System.String>(reader, "BetResult");
            this.BetProfit = GetReaderValue<System.Decimal>(reader, "BetProfit");
            this.SetTime = GetReaderValue<System.DateTime>(reader, "SetTime");
        }

        internal override System.Data.SqlClient.SqlParameter[] BuildInsertParamter()
        {
            BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection paramterList = new BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection();
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@AccountName", System.Data.SqlDbType.VarChar, 50));
            paramterList["@AccountName"].Value = this.AccountName;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@AccountPos", System.Data.SqlDbType.VarChar, 5));
            paramterList["@AccountPos"].Value = this.AccountPos;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@TableNo", System.Data.SqlDbType.TinyInt, 1));
            paramterList["@TableNo"].Value = this.TableNo;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@BetDirection", System.Data.SqlDbType.VarChar, 5));
            paramterList["@BetDirection"].Value = this.BetDirection;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@BetSize", System.Data.SqlDbType.Decimal, 9));
            paramterList["@BetSize"].Value = this.BetSize;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@BetTime", System.Data.SqlDbType.DateTime));
            paramterList["@BetTime"].Value = this.BetTime;
            return paramterList.ToArray();
        }

        internal override System.Data.SqlClient.SqlParameter[] BuildUpdateParamter()
        {
            BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection paramterList = new BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection();
            return paramterList.ToArray();
        }

        internal override string GetInsertCommandText()
        {
            string sqlcmd = @"insert dbo.[Bets]([AccountName],[AccountPos],[TableNo],[BetStatus],[BetDirection],[BetSize],[BetTime])
                          values( @AccountName, @AccountPos, @TableNo, 0, @BetDirection, @BetSize, @BetTime)
                          select * from dbo.[Bets] where [BetID] = @@IDENTITY
                        ";
            return sqlcmd;
        }

        internal override string GetUpdateCommandText()
        {
            string sqlcmd = @"";
            return sqlcmd;
        }
    }

}
